﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Net.Sockets;
using Traceability.Commont.Domains;
using Traceability.Commont.Domains.AnimalsDomainFiles;
using Traceability.Commont.DTOs;
using Traceability.Commont.DTOs.CommontFiles;
using U.Enterprise.Api.Applications.AdmissionRegistrationFile;
using U.Enterprise.Api.Applications.Client;
using U.Enterprise.Api.Applications.EnterpriseFiles;
using U.Enterprise.Api.Applications.Scalesetting;

namespace U.Enterprise.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class EnterpriseController : ControllerBase
    {
        private readonly IMediator _mediator;

        public EnterpriseController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 添加企业实体
        /// </summary>
        /// <param name="info">企业实体</param>
        /// <returns>反回类型实体</returns>
        [HttpPost]
        public async Task<Resqults> AddEnterprice(EnterpriseCreateCommand info)
        {
            try
            {
                var res = await _mediator.Send(info);
                return res;
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 获取企业数据
        /// </summary>
        /// <param name="info">分页查询实体</param>
        /// <returns>返回满足条件的数据</returns>
        [HttpPost]
        public async Task<PageDTO<Enterprises>> GetEnterprises(EnterpriseListCommand info)
        {
            try
            {
                var res = await _mediator.Send(info);
                return res;
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 添加客户
        /// </summary>
        /// <param name="info">客户实体</param>
        /// <returns>返回响应实体</returns>
        [HttpPost]
        public async Task<Resqults> addClients(ClientCreateCommand info)
        {
            try
            {
                var res = await _mediator.Send(info);
                return res;
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 客户显示
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Resqults> SearchClients(ClientSearchCommand info)
        {
            return await _mediator.Send(info);
        }
        /// <summary>
        /// 客户逻辑删除
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Resqults> DeleteClients(ClientDeleteCommand info)
        {
            return await _mediator.Send(info);
        }
        /// <summary>
        /// 修改客户表
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Resqults> UpdateClients(ClientUpdateCommand info)
        {
            return await _mediator.Send(info);
        }
        /// <summary>
        /// 进场登记
        /// </summary>
        /// <param name="info">进场登记实体</param>
        /// <returns>返回响应类型实体</returns>
        [HttpPost]
        public async Task<Resqults> CreateApproacgh(ApproachCreateCommand info)
        {
            try
            {
                var res = await _mediator.Send(info);
                return res;
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 查询进场批次
        /// </summary>
        /// <param name="Batch">进场批次</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Resqults> SelectApproachBatch(string Batch)
        {
            try
            {
                var res = await _mediator.Send(new ApproachSelectApproachBatchCommand() { ApproachBatch = Batch });
                return res;
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 查询进场等级信息列表
        /// </summary>
        /// <param name="info">进场等级DTO</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageDTO<Approach>> SelectApproachList(ApproachListCommand info)
        {
            try
            {
                var res = await _mediator.Send(info);
                return res;
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 根据进场编号查询进场登记信息
        /// </summary>
        /// <param name="ApproachNo">进场登记编号</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Resqults<Approach>> SelectApproachNo(string ApproachNo)
        {
            try
            {
                var res = await _mediator.Send(new ApproachSelectNoCommand() { ApproachNo = ApproachNo });
                return res;
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 添加活出称重信息
        /// </summary>
        /// <param name="info">活畜称重实体</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Resqults> AddLiveAnimaWeighing(LiveAnimalWeighingCreateCommand info)
        {
            try
            {
                var res = await _mediator.Send(info);
                return res;
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 活畜称重新增页数据显示
        /// </summary>
        /// <returns>返回相应DTO</returns>
        [HttpGet]
        public async Task<Resqults<LiveAnimalWeighingListDTO>> LiveAddList()
        {
            try
            {
                var res = await _mediator.Send(new LiveAnimalWeightListCommand());
                return res;
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 活畜列表+查询
        /// </summary>
        /// <param name="info">查询信息</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Resqults<LiveAnimalWeightSelectListDTO>> SelecrLiveList(LiveAnimalWeightSelectListCommand info)
        {
            try
            {
                var res = await _mediator.Send(info);
                return res;
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 活畜称重逻辑删除
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Resqults> DeleteLive(LiveAnimalWeightDeleteCommand cmd)
        {
            return await _mediator.Send(cmd);
        }
        /// <summary>
        /// 进场登记显示绑定下拉框
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Resqults> Searchapp(ApproachSearchCommand info)
        {
            return await _mediator.Send(info);
        }
        /// <summary>
        /// 根据称重单据号获取称重数据
        /// </summary>
        /// <param name="info">称重单据号</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Resqults<LiveAnimalweighing>> LiveNoInfo(LiveUpdateSelectCommand info)
        {
            try
            {
                var res= await _mediator.Send(info);
                return res;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
